Skip to content

perf(server): a remote fetch no longer makes a branch list read twice - #1027

Merged
badcuban merged 1 commit into
mainfrom
perf/list-refs-reread
Nov 20, 2026
Merged

badcuban merged 1 commit into
mainfrom
perf/list-refs-reread

Conversation

@badcuban

Copy link
Copy Markdown
Collaborator

Every branch listing (listRefs) starts a background fetch of remote branches, at most every two minutes per repository. When that fetch finished, it used the same invalidation as a change made through the app and bumped the list's generation. So a listing that was reading when the fetch landed threw its read away and read again. Server traces showed a listing paying for both reads, 3.2s and then 1.1s.

A finished background fetch now calls markRemoteRefsFetchedByCommonDir, which:

  • bumps only the epoch, so later listings read fresh
  • drops the shared fresh-read entry for the current generation from listRefsRefreshCache (fresh reads are shared for 5s), so the next fresh listing doesn't reuse the read from before the fetch
  • leaves the generation alone, so a listing already reading keeps its answer, as if it had come a moment sooner

Changes made through the app (a branch created, switched or deleted) still bump the generation and force a re-read.

Tests. New: "shows branches a background fetch brought in to the next fresh listing". It fails without the shared-entry drop (checked twice) and passed three times in a row with it. 75 driver tests and 260 git-related server tests pass, along with fmt, lint and typecheck.

Review. Reviewed by GPT-6.2-Astra: no defect found in the cache change. It flagged that the new test's first assertion could fail when the fetch beats the first read; that assertion is removed. It also noted the test doesn't prove the double read itself is gone. Proving that would mean holding a snapshot read open mid-flight through the driver's git calls, which isn't worth the hook.

Every branch listing starts a background fetch of remote branches (at most
every two minutes per repository). When that fetch finished it used the
same invalidation as a change made through the app, bumping the
generation, so a listing that was reading when it landed threw its read
away and read again: traces showed a listing paying 3.2s and then 1.1s.

A finished background fetch now only bumps the epoch, so later listings
read fresh, and drops the shared fresh-read entry for the current
generation, so the next fresh listing (shared for a few seconds) doesn't
reuse the read from before the fetch. A listing already reading keeps its
answer, as if it had come a moment sooner. Changes made through the app
still bump the generation and force a re-read.
@vercel

vercel Bot commented Nov 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
threadlines Skipped Skipped Nov 20, 2026 8:06pm UTC

Request Review

@badcuban
badcuban added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit 25e6bab Nov 20, 2026
23 checks passed
@badcuban
badcuban deleted the perf/list-refs-reread branch November 20, 2026 20:17

This branch was previously deployed

1 inactive deployment
Preview — 509c8f69 Deployed Nov 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant